package com.wuyou.simple;

import cn.hutool.core.collection.EnumerationIter;

import java.util.Arrays;

/**
 * @Description 26. 删除有序数组中的重复项
 * @Author yh.zhang
 * @Date 2023/11/22 10:10
 */
public class RemoveDuplicates {


    public static void main(String[] args) {
        int[] nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
//        int[] nums = {1, 1, 2};
        System.out.println(solution_1(nums));
    }


    public static int solution_2(int[] nums){
        int slow = 1, fast = 1;
        while (fast < nums.length) {
            if(nums[fast] != nums[fast - 1]){
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
    public static int solution_1(int[] nums) {
        int ans = nums.length;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                ans--;
                nums[i] = Integer.MAX_VALUE - 1;
            }
        }
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == Integer.MAX_VALUE - 1) {
                nums[i] = 0;
            }
        }
        return ans;
    }
}
